<?php
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title='购买用户广告位';
include_once './header.php';
if($conf['adver_open']!=1)showmsg('错误', '授权平台未开放广告系统', 4, './');
if($conf['adver_buy_open']!=1)showmsg('错误', '授权平台未开放在线购买广告位！', 4, './');
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                购买用户广告位
            </div>
            <div class="card-body">
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">广告标题：</label>
                        <input type="text" name="title" class="form-control" lay-verType="tips" lay-verify="required"/>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">跳转地址：</label>
                        <input type="text" name="url" value="http://" class="form-control" lay-verType="tips" lay-verify="required"/>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">文字颜色：<div id="colorpicker"></div></label>
                        <input type="text" name="colour" id="colorpicker-form-input" placeholder="点击颜色选择器选择颜色" class="form-control" lay-verType="tips" lay-verify="required"/>
                    </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_addadver">购 买</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form', 'colorpicker'], function () {
    var form = layui.form;
    var colorpicker = layui.colorpicker;
    form.on('submit(submit_addadver)', function (data) {
        layer.alert('是否要执行当前操作？', {
            icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                addadver();
            }
        });
        return false;
    });
    colorpicker.render({
        elem: '#colorpicker',color: '#1c97f5',done: function(color){
            $('#colorpicker-form-input').val(color);
        }
    });
});
function addadver() {
    var title=$("input[name='title']").val();
    var url=$("input[name='url']").val();
    var colour=$("input[name='colour']").val();
    if(title==""){
        layer.msg("请输入广告标题", {icon: 5});
        return false;
    }else if(url=="http://" || url=="https://"){
        layer.msg("请输入广告跳转地址", {icon: 5});
        return false;
    }
    var ii = layer.msg('正在购买广告位中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type : "POST",
        url : "ajax.php?act=addver",
        data : {title:title,url:url,colour:colour},
        dataType : "json",
        success : function(data) {
            layer.close(ii);
            if(data.code == 0){
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.href = './adverlist.php';
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    });
    return false;
};
</script>